<?php

namespace App\Policies;

use App\Models\Device;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class DevicePolicy
{
    use HandlesAuthorization;
    /**
     * Determine whether the user can delete the model.
     *
     * @param  \App\Models\User  $user
     * @param  \App\Models\User  $model
     * @return mixed
     */
    public function updateCover(User $user, Device $model)
    {
        if (in_array($user->role_code, ['ADMIN', 'REPAIRER','AGENT','MERCHANT'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
    public function activation(User $user){
        if (in_array($user->role_code, ['ADMIN'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
    public function unBind(User $user){
        if (in_array($user->role_code, ['ADMIN'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
    public function viewAny(User $user)
    {
        if (in_array($user->role_code, ['ADMIN', 'REPAIRER','AGENT','MERCHANT','STAFF','DISTRIBUTOR'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
    public function add(User $user)
    {
        if (in_array($user->role_code, ['ADMIN'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
    public function update(User $user)
    {
        if (in_array($user->role_code, ['ADMIN', 'REPAIRER'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
    public function repair(User $user)
    {
        if (in_array($user->role_code, ['ADMIN', 'REPAIRER'])) {
            return self::allow();
        }
        self::deny('没有权限访问');
    }
}
